package views;

import java.awt.BorderLayout;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import presenters.MaintHistoryReportPresenter;
import presenters.RevenueReportPresenter;

public class MaintHistoryReportPanel extends JPanel{
	private static final long serialVersionUID = 1L;
	JTable table;
	Object[][] addInData;
	String[] columnNames =  {"Car",
            "Date-Time",
            "Employee",
            "Problem",
       };
	private MaintHistoryReportPresenter myPresenter;

	public MaintHistoryReportPanel() {
		// TODO
		
		Object[][] data = {
				{"1","1","1","1"}
			};
		
		table = new JTable(data, columnNames);
		add(new JScrollPane(table), BorderLayout.CENTER);
		
		myPresenter = new MaintHistoryReportPresenter(this);
	}
	
	public void addData(ResultSet rs) {
		
		ArrayList<Object> newData = new ArrayList<Object>();
		try {
			rs.first();
			while(rs.next()) {
				String car2 = rs.getString("CAR");
				String dateTime2 = rs.getString("DATE_TIME");
				String employee2 = rs.getString("EMPLOYEE");
				String problem2 = rs.getString("PROBLEM");
				newData.add(car2);
				newData.add(dateTime2);
				newData.add(employee2);
				newData.add(problem2);
				}
				addInData = new Object[newData.size()/4][3];
				int k = 0;
				for (int i = 0; i < newData.size()/4; i++)
				{
					for (int j = 0; j < 4; j++)
					{
						addInData[i][j] = newData.get(k);
						k++;
					}
				}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		table = new JTable(addInData, columnNames);
		revalidate();
	}

	public MaintHistoryReportPresenter getMyPresenter() {
		// TODO Auto-generated method stub
		return myPresenter;
	}
}
